import React from "react";
import Parent from './components/parent'
// class方式 创建组件

class App2 extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      count: 1,
      isLogin:false,
    };
    this.changeValue = this.changeValue.bind(this);
  }

  async changeValue() {
    await this.setStateAsync({
      count: this.state.count + 1,
      isLogin:!this.state.isLogin
    });
    console.log(this.state.count)
  }

  setStateAsync(state) {
    return new Promise((resolve) => {
      this.setState(state, resolve);
    });
  }

  render() {
    let showView =this.state.isLogin?<div>已经登录了</div>:<div>请登录</div>
    return (
      <div>
          {showView}
          {this.state.count}
          <button onClick={this.changeValue}>增加</button>
          <Parent />
      </div>
    );
  }
}

export default App2;
